<%@page import="com.carrental.entity.CarList"%>
<%@page import="com.carrental.service.CarListService"%>
<%@page import="com.carrental.entity.User"%>
<%@page import="com.carrental.entity.CarRental"%>
<%@page import="java.util.List"%>
<%@page import="com.carrental.service.CarRentalService"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>我的订单</title>
<style type="text/css">
	*{
		margin: 0;
		padding: 0;
	}
	
	html,body{
		width: 100%;
		height: 100%;
		background-color: #f2f2f2;
	}
	
	.head{
		width: 100%;
		height: 50px;
		line-height: 50px;
		background-color: #FA8258;
		color: #ffffff;
	}
	.head-content{
		width: 900px;
		margin: auto;
	}
	.head-content h2{
		float: left;
		margin-right: 10px;
	}
	.head-content a{
		float: left;
		margin-right: 10px;
	}
	.main{
		width: 100%;
	}
	.main-content{
		padding: 20px;
		width: 900px;
		margin: auto;
		background: #ffffff;
	}
	table{
		width: 100%;
		text-align: center;
	}
</style>
</head>
<body>
	<div class="head">
		<div class="head-content">
			<h2>汽车租赁网</h2>
			<a href="index.jsp">首页</a>
			<a href="carRentalList.jsp">我的订单</a>
			<a href="userUpdate.jsp">个人信息</a>
			<a href="LogoutServlet">退出</a>
		</div>
	</div>
	<div class="main">
		<div class="main-content">
			<table>
				<thead>
					<tr>
						<th>订单编号</th>
						<th>汽车型号</th>
						<th>租赁数量</th>
						<th>订单总额</th>
						<th>租赁开始时间</th>
						<th>租赁结束时间</th>
						<th>下单时间</th>
					</tr>
				</thead>
				<tbody>
					<%
						String username = ((User) request.getSession().getAttribute("user")).getUsername();
						CarRentalService carRentalService = new CarRentalService();
						List<CarRental> carRentals = carRentalService.selectByUsername(username);
			
						CarListService carListService = new CarListService();
						
						for (CarRental carRental : carRentals) {
							CarList carList = carListService.selectById(carRental.getCarId());
							
							out.print("<tr>");
							out.print("<td>" + carRental.getId() + "</td>");
							out.print("<td>" + carList.getModel() + "</td>");
							out.print("<td>" + carRental.getRentalNum() + "</td>");
							out.print("<td>" + carRental.getRentalTotal() + "</td>");
							out.print("<td>" + carRental.getRentalStartDatetime() + "</td>");
							out.print("<td>" + carRental.getRentalEndDatetime() + "</td>");
							out.print("<td>" + carRental.getCreateDatetime() + "</td>");
							out.print("</tr>");
						}
						
					%>
				</tbody>
			</table>
		</div>
	</div>
</body>
</html>